package com.myth.thread.exer;

/**
 * 联系：创建两个线程，分别执行不同的事情
 *
 *
 * @author
 * @create 2021/8/6
 */
public class ThreadDemo {
    public static void main(String[] args) {
//        Thread m1 = new MyThread1();
//        Thread m2 = new MyThread2();
//
//        m1.start();
//        m2.start();


        //创建Thread类的匿名子类的方法
        new Thread() {
            @Override
            public void run() {
                for (int i = 0; i < 100; i++) {
                    if (i % 2 == 0) {
                        System.out.println(i);
                    }
                }
            }
        } .start();


        new Thread() {
            @Override
            public void run() {
                for (int i = 0; i < 100; i++) {
                    if (i % 2 != 0) {
                        System.out.println(i);
                    }
                }
            }
        } .start();

    }




}

class MyThread1 extends Thread {

    @Override
    public void run() {
        for (int i = 0; i < 100; i++) {
            if (i % 2 == 0) {
                System.out.println(i);
            }
        }
    }
}


class MyThread2 extends Thread {

    @Override
    public void run() {
        for (int i = 0; i < 100; i++) {
            if (i % 2 != 0) {
                System.out.println(i);
            }
        }
    }
}